package avicit.bdp.dcs.desensitization.service;

import avicit.bdp.common.base.BaseService;
import avicit.bdp.dcs.desensitization.dao.DataMaskingMethodDao;
import avicit.bdp.dcs.desensitization.dto.DataMaskingMethodDto;
import avicit.platform6.core.exception.BusinessException;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2021-08-02
 * @类说明：DataMaskingService
 * @修改记录：
 * @注意事项：
 * @主要功能：数据脱敏管理服务
 */
@Service
@Transactional
@DependsOn("springApplicationContext")
public class DataMaskingMethodService extends BaseService<DataMaskingMethodDao, DataMaskingMethodDto> {
    /**
     * 获取算法类型
     * @return
     */
    public List<String> getAllAlgoType() {
        return this.mapper.getAllDataMaskingType();
    }

    /**
     * 根据算法类型获取所有算法
     * @param algoType
     * @return
     */
    public List<DataMaskingMethodDto> getMethodByAlgoType(String algoType) {
        return this.mapper.getMethodByAlgoType(algoType);
    }

    /**
     * 根据主键ID获取脱敏方法
     * @param id
     * @return
     */
    public DataMaskingMethodDto queryDataMaskingDto(String id) {
        if (id == null) {
            throw new BusinessException("查询数据脱敏方法失败，id为null.");
        }

        DataMaskingMethodDto queryRet = selectByPrimaryKey(id);
        if (queryRet == null) {
            throw new BusinessException(String.format("未找到指定脱敏方法，id=%s.", id));
        }

        return queryRet;
    }
}
